package com.neo4j.neo4jcloud.controller;

import com.neo4j.neo4jcloud.entity.Person;
import com.neo4j.neo4jcloud.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author kabuqinuo
 * @date 2020/3/26 13:07
 */

/**
 * 单个节点person增删查接口
 */
@RestController
@RequestMapping(value = "person")
public class PersonController {

    @Autowired
    private PersonService personService;


    @PostMapping
    public ResponseEntity<Person> addPerson(HttpServletRequest request, @RequestBody Person person, HttpServletResponse response){
        return ResponseEntity.ok(personService.addPerson(person));
    }

    @GetMapping
    public ResponseEntity<Person> findPerson(HttpServletRequest request, @RequestParam(value = "id") Long id, HttpServletResponse response){
        return ResponseEntity.ok(personService.findOneById(id));
    }

    @DeleteMapping
    public String deletePerson(HttpServletRequest request, @RequestParam(value = "id") Long id, HttpServletResponse response){
        personService.deletePerson(id);
        return "success";
    }
}
